package parser

import (
	"learngo/crawler/engine"
	"regexp"
	"strconv"
)
const womenReg	=`<div class="list-item"><div class="photo"><a href="[^"]+" target="_blank"><img src="([^\?]+)\?[^"]+" alt="[^"]+"></a></div> <div class="content"><table><tbody><tr><th><a href="([^"]+)" target="_blank">([^<]+)</a></th></tr> <tr><td width="180"><span class="grayL">性别：</span>([^<]+)</td> <td><span class="grayL">居住地：</span>([^<]+)</td></tr> <tr><td width="180"><span class="grayL">年龄：</span>([^<]+)</td> <td><span class="grayL">学   历：</span>([^<]+)</td> </tr> <tr><td width="180"><span class="grayL">婚况：</span>([^<]+)</td> <td width="180"><span class="grayL">身   高：</span>([^<]+)</td></tr></tbody></table> <div class="introduce">([^<]+)</div>`
const manReg	=`<div class="list-item"><div class="photo"><a href="[^"]+" target="_blank"><img src="([^\?]+)\?[^"]+" alt="[^"]+"></a></div> <div class="content"><table><tbody><tr><th><a href="([^"]+)" target="_blank">([^<]+)</a></th></tr> <tr><td width="180"><span class="grayL">性别：</span>([^<]+)</td> <td><span class="grayL">居住地：</span>([^<]+)</td></tr> <tr><td width="180"><span class="grayL">年龄：</span>([^<]+)</td>  <td><span class="grayL">月   薪：</span>([^<]+)</td></tr> <tr><td width="180"><span class="grayL">婚况：</span>([^<]+)</td> <td width="180"><span class="grayL">身   高：</span>([^<]+)</td></tr></tbody></table> <div class="introduce">([^<]+)</div>`
func ParseCity(content []byte)engine.ParseResult{
	var result engine.ParseResult
	re:=regexp.MustCompile(womenReg)
	womenS:=re.FindAllSubmatch(content,-1)
	for _,m:=range womenS{
		var person engine.Profile
		person.Picture	=string(m[1])
		person.UserUrl	=string(m[2])
		person.Name		=string(m[3])
		person.Gender	=string(m[4])
		person.Local	=string(m[5])
		age,err:=strconv.Atoi(string(m[6]))
		if err!=nil {
			person.Age=0
		}else{
			person.Age=age
		}
		person.Education	=string(m[7])
		person.Marriage		=string(m[8])
		height,err:=strconv.Atoi(string(m[9]))
		if err!=nil {
			person.Height=0
		}else{
			person.Height=height
		}
		person.UserDesc		=string(m[10])
		result.Items=append(result.Items,person)
	}
	re2:=regexp.MustCompile(manReg)
	manS:=re2.FindAllSubmatch(content,-1)
	for _,m:=range manS{
		var person engine.Profile
		person.Picture	=string(m[1])
		person.UserUrl	=string(m[2])
		person.Name		=string(m[3])
		person.Gender	=string(m[4])
		person.Local	=string(m[5])
		age,err:=strconv.Atoi(string(m[6]))
		if err!=nil {
			person.Age=0
		}else{
			person.Age=age
		}
		person.Salary	=string(m[7])
		person.Marriage		=string(m[8])
		height,err:=strconv.Atoi(string(m[9]))
		if err!=nil {
			person.Height=0
		}else{
			person.Height=height
		}
		person.UserDesc		=string(m[10])
		result.Items=append(result.Items,person)
	}
	return result
}
